package 常用类.日期;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/*
    第三代日期：
        LocalDate:日期-年月日
        LocalTime:时分秒
        LocalDateTime:年月日时分秒
 */
public class 日期类 {
    public static void main(String[] args) {
        LocalDateTime localDateTime = LocalDateTime.now();

        System.out.println("年：" +localDateTime.getYear());
        System.out.println("月：" +localDateTime.getMonthValue());
        System.out.println("日：" +localDateTime.getDayOfMonth());
        System.out.println("时：" +localDateTime.getHour());
        System.out.println("分：" +localDateTime.getMinute());
        System.out.println("秒：" +localDateTime.getSecond());

        LocalDate now1 = LocalDate.now();

        //使用DateTimeFormat格式化
        DateTimeFormatter da = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss E");
        System.out.println(da.format(localDateTime));


        Instant now = Instant.now();
        System.out.println(now);
        System.out.println(Date.from(now));
        Date from = Date.from(now);

        //plusYears，多少年以后的时间
        LocalDateTime localDateTime1 = localDateTime.plusYears(5);
        System.out.println(da.format(localDateTime1));

    }
}
